package qqgroupdata.process.service;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import qqgroupdata.process.mapper.DbDataSelectMapper;
import qqgroupdata.process.model.QQNum;
import qqgroupdata.process.model.Qun;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class DbDataSelectService {
    @Resource
    DbDataSelectMapper dbDataSelectMapper;

    /**
     * 根据QQ号查询
     *
     * @param qqNum
     * @return
     */
    public List<QQNum> selectQQNum(Integer qqNum) {
        String qNumDataNmae = "QnumData.dbo.QnumData" + (qqNum / 1000000);

        List<QQNum> qqNums = dbDataSelectMapper.selectQQNum(qNumDataNmae, qqNum);
        for (QQNum q : qqNums) {
            String qunInfoTableName = "QunInfo" + (q.getQunnum() / 10000000 + 1) + ".dbo.QunList" + (q.getQunnum() / 1000000 + 1);
            Map<String, String> map = dbDataSelectMapper.selectOnlyQunInfo(qunInfoTableName, q.getQunnum());
            if (map != null) {
                q.setTitle(map.get("title"));
            }
        }
        return qqNums;
    }


    /**
     * 根据QQ群查询
     *
     * @param qQun
     * @return
     */
    public List<Qun> selectQqun(Integer qQun) {
        String groupTableName = "GroupData" + (qQun / 10000000 + 1) + ".dbo.Group" + (qQun / 100000 + 1);
        String qunInfoTableName = "QunInfo" + (qQun / 10000000 + 1) + ".dbo.QunList" + (qQun / 1000000 + 1);
        List<Qun> quns = dbDataSelectMapper.selectQqun(groupTableName, qunInfoTableName, qQun);
        return quns;
    }
}
